package cn.tedu.circle.passport.controller;

import cn.tedu.circle.common.web.JsonResult;
import cn.tedu.circle.passport.pojo.param.UserLoginInfoParam;
import cn.tedu.circle.passport.pojo.vo.UserLoginResultVO;
import cn.tedu.circle.passport.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

@RestController
@RequestMapping("/users")
@Api(tags = "1.单点登录")
@Validated
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 100)
    public JsonResult login(@Valid UserLoginInfoParam userLoginInfoParam,
                            @ApiIgnore HttpSession session){
        UserLoginResultVO loginResult = userService.login(userLoginInfoParam);
        session.setAttribute("loginResult",loginResult);
        return JsonResult.ok(loginResult);
    }
}
